package com.example.demo.information.controller;

import com.example.demo.information.service.InformationService;
import com.example.demo.system.utility.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.Date;

/**
 * 数据采集
 */
@RequestMapping("information")
@RestController
public class InformationController {

    @Autowired
    private InformationService informationService;

    /**
     * 数据采集模块
     * 查询每个设备的最新一条数据
     */
    @RequestMapping("getList")
    public Result getList(@RequestParam(value = "pageNum") Integer pageNum,
                          @RequestParam(value = "pageSize") Integer pageSize,
                          @RequestParam(value = "name", required = false) String name) {
        return informationService.getList(pageNum, pageSize, name);
    }

    /**
     * 数据采集模块
     * 查询单个设备的数据集合
     */
    @RequestMapping("get")
    public Result getPage(@RequestParam(value = "pageNum") Integer pageNum,
                          @RequestParam(value = "pageSize") Integer pageSize,
                          @RequestParam(value = "deviceId") String deviceId,
                          @RequestParam(value = "startTime", required = false) String startTime,
                          @RequestParam(value = "endTime", required = false) String endTime) {
        return informationService.getPage(pageNum, pageSize, deviceId, startTime, endTime);
    }

    /**
     * 数据采集模块
     * 查询单个设备的数据集合
     * 获取折线图数据格式
     */
    @RequestMapping("getLineChart")
    public Result getLineChart(String deviceId) {
        return informationService.getLineChart(deviceId);
    }

    /**
     * 数据报表模块-采集数据
     */
    @RequestMapping("getDataList")
    public Result getDataList(@RequestParam(value = "pageNum") Integer pageNum,
                              @RequestParam(value = "pageSize") Integer pageSize,
                              @RequestParam(value = "spaceId", required = false) Integer spaceId,
                              @RequestParam(value = "startTime", required = false) String startTime,
                              @RequestParam(value = "endTime", required = false) String endTime) {
        return informationService.getDataList(pageNum, pageSize, spaceId, startTime, endTime);
    }

    /**
     * 数据报表模块-生成报告
     */
    @RequestMapping("addReport")
    public Result addReport(@RequestParam(value = "spaceId", required = false) Integer spaceId,
                            @RequestParam(value = "startTime", required = false) String startTime,
                            @RequestParam(value = "endTime", required = false) String endTime) {
        return informationService.addReport(spaceId, startTime, endTime);
    }

    /**
     * 数据报表模块-报告列表
     *
     */
    @RequestMapping("getReportList")
    public Result getReportList(@RequestParam(value = "pageNum") Integer pageNum,
                                @RequestParam(value = "pageSize") Integer pageSize,
                                @RequestParam(value = "spaceId", required = false) Integer spaceId,
                                @RequestParam(value = "startTime", required = false) String startTime,
                                @RequestParam(value = "endTime", required = false) String endTime) {
        return informationService.getReportList(pageNum, pageSize, spaceId, startTime, endTime);
    }

    /**
     *  数据报表模块-报告列表 删除
     */
    @RequestMapping("deleteReport")
    public Result deleteReport(Integer id) {
        return informationService.deleteReport(id);
    }

}
